In C, what is the meaning of following function prototype with empty p...
Function Prototype with Empty Parameter List in C
In C, a function prototype with an empty parameter list means that the function can be called with any number of parameters of any types. Let's understand this in detail.
Function Prototype
A function prototype is a declaration that specifies the function name and its parameters, without providing the function definition. It gives the compiler information about the function's return type and the number and types of its parameters.
Empty Parameter List
An empty parameter list in a function prototype means that the function does not have any parameters. In C, an empty parameter list is denoted by leaving the parentheses empty, like `void fun()`. This indicates that the function does not require any arguments.
Meaning of an Empty Parameter List
When a function prototype has an empty parameter list, it means that the function can be called with any number of parameters of any types. This is because the function prototype does not specify any specific parameters, allowing flexibility in the number and types of arguments passed to the function.
Examples
Let's consider an example to understand this concept further:
```
#include
void fun();
int main() {
fun(); // Function call without any parameter
fun(10); // Function call with one integer parameter
fun(10, 20); // Function call with two integer parameters
fun(3.14, "Hello"); // Function call with one double and one string parameter
return 0;
}
void fun() {
printf("Function called\n");
}
```
In the above example, the function `fun` is declared with an empty parameter list in the function prototype. This allows the function to be called without any parameters (`fun()`), with one integer parameter (`fun(10)`), with two integer parameters (`fun(10, 20)`), or with any other combination of parameters.
Conclusion
In C, a function prototype with an empty parameter list indicates that the function can be called with any number of parameters of any types. This provides flexibility in the function call, allowing for different combinations of arguments to be passed to the function.
In C, what is the meaning of following function prototype with empty p...
Empty list in C mean that the parameter list is not specified and function can be called with any parameters. In C, to declare a function that can only be called without any parameter, we should use "void fun(void)" As a side note, in C++, empty list means function can only be called without any parameter. In C++, both void fun() and void fun(void) are same.
To make sure you are not studying endlessly, EduRev has designed Computer Science Engineering (CSE) study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Computer Science Engineering (CSE).